package com.sky.wsp.weixin.config;

import com.sky.wsp.weixin.config.properties.WeixinProperties;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(WeixinProperties.class)
public class WeixinConfig {

    @Bean
    public WxCpServiceImpl wxCpService(WeixinProperties properties) {
        WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId(properties.getCorpId());
        configStorage.setAgentId(properties.getAgentId());
        configStorage.setCorpSecret(properties.getSecret());
        configStorage.setToken(properties.getToken());
        configStorage.setAesKey(properties.getAesKey());

        WxCpServiceImpl cpService = new WxCpServiceImpl();
        cpService.setWxCpConfigStorage(configStorage);
        return cpService;
    }

}
